package cn.ts.android.attendance.sender;

import cn.ts.android.attendance.generator.DataBootrap;
import cn.ts.android.attendance.model.Attendence;

import java.util.List;

public class Sender {




    /**
     *
     * 有tag数据先取tag
     * 获取数据库20条数据，如果不足20条则取所有
     *
     */
    public  List<Attendence> readyData (String re){


        if (re!=null)
            DataBootrap.getSingleton().getAttenDances();


     return   DataBootrap.getSingleton().getAttenDances();


    }



    /**
     * 给这一批次的数据打上tag
     *
     */
    public  AttendanceBindTag readyDataTag (List<Attendence> attendenceList,String serRequstNum){


        for(Attendence attendence:attendenceList ){

            attendence.setSerReqNum(serRequstNum);

        }

        DataBootrap.getSingleton().updateAttenDances(attendenceList);

        return new AttendanceBindTag(attendenceList,serRequstNum);

    }


    /**
     * 先生成一个serquestNum
     * @return
     */
    public  void senderReuqestNum(String serRequstNum){


        if (serRequstNum==null)
         serRequstNum=String.valueOf(System.currentTimeMillis());
        //调用http方法




    }


    /**
     * 回调
     * @param requstNum
     */
    public void DataSender(String requstNum){


        if (requstNum==null) {
            senderReuqestNum(null);
        }else{
            //回掉是否可用如果不可用则删除掉这一批次的数据
            senderReuqestNum(null);


            List<Attendence> attendences=readyData(requstNum);
            AttendanceBindTag attendanceBindTag=readyDataTag(attendences,requstNum);
            //调用http方法

        }
    }



    public void DataSenderCallBack(HttpResult httpResult) throws InterruptedException {

        Thread.sleep(10000);

        //判断回掉的requst如果正常则删除数据库


        //如果不正常则把上次的senderReuqestNum传进去

        //senderReuqestNum(res);



    }

}
